#!/usr/bin/Python
# -*- coding: utf-8 -*-
import os
import urllib
import urllib2


class HtmlDownloader(object):
    def downloaderHtml(self, url):
        if url is None:
            return
        # request = urllib2.Request(url, headers=self.headers)
        response = urllib2.urlopen(url)
        if response.getcode() != 200:
            return None
        return response.read()

    def downImg(self,urllist,title):
        if urllist is None:
            return
        name = 1
        print 'downing .....'
        path = 'file/' + title
        if not os.path.exists(path):
            os.mkdir(path)
            for imgurl in urllist:
                urllib.urlretrieve(imgurl,path+'\%s.jpg' %(name))
                name += 1
        else:
            print '文件已下载'
        print 'Get ', len(urllist), ' images!'
